#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2018, Intel Corporation
#
#
# pmempool_check/TEST16 -- test for checking and fixing pool files crtime
#

. ../unittest/unittest.sh

require_test_type medium

require_fs_type pmem non-pmem

setup

POOLSET=$DIR/pool.set
POOL_P1=$DIR/pool.p1
POOL_P2=$DIR/pool.p2
LOG=out${UNITTEST_NUM}.log
rm -f $LOG && touch $LOG

create_poolset $POOLSET 20M:$POOL_P1:z 20M:$POOL_P2:z
expect_normal_exit $PMEMPOOL$EXESUFFIX create log $POOLSET

TIME=$($DATE +"%s")
let "FUTURE_TIME=$TIME+60*60"
let "PAST_TIME=$TIME-60*60"
PAST_TIME=$($DATE -d @$PAST_TIME +"%y%m%d%H%M")
$PMEMSPOIL -v $POOL_P1 pool_hdr.crtime=$FUTURE_TIME >> $LOG
touch -mt $PAST_TIME $POOL_P1

expect_abnormal_exit $PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG
expect_abnormal_exit $PMEMPOOL$EXESUFFIX check -vry $POOLSET >> $LOG
expect_normal_exit $PMEMPOOL$EXESUFFIX check -vrya $POOLSET >> $LOG
expect_normal_exit $PMEMPOOL$EXESUFFIX info $POOLSET &> /dev/null

check

pass
